from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Display.SimpleGui import init_display
from OCC.Core.STEPControl import STEPControl_Writer, STEPControl_StepModelType  # 修改导入路径

# 创建一个盒子，其尺寸为100x100x50
box = BRepPrimAPI_MakeBox(100, 100, 50).Shape()

# 初始化显示
display, start_display, add_menu, add_function_to_menu = init_display()

# 将盒子添加到显示窗口
display.DisplayShape(box, update=True)

# 启动事件循环
start_display()

# 导出为STP文件
step_writer = STEPControl_Writer()
status = step_writer.Transfer(box, STEPControl_StepModelType.STEPControl_FacetedBrep)
if status == 1:
    step_writer.Write("box.stp")
    print("STP文件导出成功！")
else:
    print("STP文件导出失败！")